package com.micro.service.account.server.biz.impl;

import com.micro.service.account.server.biz.UserBaseBiz;
import com.micro.service.account.server.dao.UserBaseMapper;
import com.micro.service.account.server.model.UserBase;
import com.micro.service.account.share.dto.UserBaseDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lvxiucai
 * @description 用户信息业务层
 * @date 2020/4/9
 */
@Service
@Slf4j
public class UserBaseBizImpl implements UserBaseBiz {

    @Autowired
    private UserBaseMapper userBaseMapper;


    @Override
    public UserBaseDto selectByUsername(String username) {
        if(StringUtils.isBlank(username)){
            log.error("biz层调用selectByUsername用户名为空，name:{}",username);
            return null;
        }
        UserBase userBase = userBaseMapper.getByName(username);
        if(userBase == null){
            return null;
        }
        UserBaseDto userBaseDto = new UserBaseDto();
        BeanUtils.copyProperties(userBase,userBaseDto);
        return userBaseDto;
    }

    @Override
    public UserBaseDto selectByMobile(String mobile) {
        if(StringUtils.isBlank(mobile)){
            log.error("biz层调用selectByMobile用户名为空，mobile:{}",mobile);
            return null;
        }
        UserBase userBase = userBaseMapper.getByMobile(mobile);
        if(userBase == null){
            return null;
        }
        UserBaseDto userBaseDto = new UserBaseDto();
        BeanUtils.copyProperties(userBase,userBaseDto);
        return userBaseDto;
    }

    @Override
    public UserBaseDto selectByUserId(Long userId) {
        if(userId == null){
            log.error("biz层调用selectByUserId用户id为空，userId:{}",userId);
            return null;
        }
        UserBase userBase = userBaseMapper.selectByPrimaryKey(userId);
        if(userBase == null){
            return null;
        }
        UserBaseDto userBaseDto = new UserBaseDto();
        BeanUtils.copyProperties(userBase,userBaseDto);
        return userBaseDto;
    }
}
